package com.hexiang.rocketmq.consumer;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.SelectorType;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 简单批量消息消费监听器
 */
@Slf4j
@Component
@RocketMQMessageListener(topic = "test_simple_batch_spring_topic", consumerGroup = "imple-batch-spring-topic-consumer-group-spring-message", selectorExpression = "*", selectorType = SelectorType.TAG, consumeMode = ConsumeMode.CONCURRENTLY)
public class SimpleBatchMessageRocketMQListener implements RocketMQListener<List<MessageExt>> {

    @Override
    public void onMessage(List<MessageExt> messageExtList) {
        if (CollectionUtils.isNotEmpty(messageExtList)) {
            for (MessageExt message : messageExtList) {
                log.info("topic=" + message.getTopic() + ", consumeThread=" + Thread.currentThread().getName() + ", queueId=" + message.getQueueId() + ", content=" + new String(message.getBody()));
            }
        }

    }

}